﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoShopping.Model;


namespace GoShopping.BLL.SysInfo
{
    /// <summary>
    /// 相关产品 操作类
    /// </summary>
    public class RelatedPrdctBean
    {
        public IList<RelatedPrdct> GetAll()
        {
            return Databases.DBGoShopping.Select(GoShoppingNBear.RelatedPrdct).ToList<RelatedPrdct>();
        }

        public bool Add(RelatedPrdct rp)
        {
            int hasCount = Databases.DBGoShopping.Select(GoShoppingNBear.RelatedPrdct).Where(
                GoShoppingNBear.RelatedPrdct.TobeRelatedPrdctID == rp.TobeRelatedPrdctID &&
                GoShoppingNBear.RelatedPrdct.BeRelatedPrdctID == rp.BeRelatedPrdctID).ToDataSet().Tables[0].Rows.Count;
            if (hasCount > 0)
            {
                //已经有
                return false;
            }
            Databases.DBGoShopping.Insert(GoShoppingNBear.RelatedPrdct).AddColumn(
                GoShoppingNBear.RelatedPrdct.BeRelatedPrdctID, rp.BeRelatedPrdctID).AddColumn(
                GoShoppingNBear.RelatedPrdct.TobeRelatedPrdctID, rp.TobeRelatedPrdctID).Execute();
            return true;
        }

        public void Del(RelatedPrdct rp)
        {
            Databases.DBGoShopping.Delete(GoShoppingNBear.RelatedPrdct).Where(
                GoShoppingNBear.RelatedPrdct.BeRelatedPrdctID == rp.BeRelatedPrdctID &&
                GoShoppingNBear.RelatedPrdct.TobeRelatedPrdctID == rp.TobeRelatedPrdctID).Execute();
        }
    }
}
